' *** Documentation
' 
' Klenwell VB Script Template
' 
' last updated: Jun 2007
' author: klenwell@gmail.com
' 
' DESCRIPTION
'  test objects in vbs
' 
' NOTES
' 
' ____________________________________________________________________________*/

' *** DECLARATIONS
Option Explicit
' Set Files to Include Here
dim aINCLUDE(1)
aINCLUDE(1) = "dataset.class.vbs"

' Show Errors?
Const SHOW_ERRORS = True
Const HTML_BR = "<br />"

' *** SCRIPT ERROR HANDLER
' Config
dim oDictErr, iErrCount
Set oDictErr = CreateObject("Scripting.Dictionary")
iErrCount = 0

' Klenwell Error Trigger
Function kwTriggerError(sMessage)
	iErrCount = iErrCount + 1
	oDictErr.Add iErrCount, sMessage
	If SHOW_ERRORS Then: MsgBox("Error #" & iErrCount & " : " & sMessage)
	Err.Clear()
End Function

' Klenwell Error Dump
Sub kwDumpErrors
	dim sOut, vKey
	sOut = "Error Dump ("&iErrCount&" Errors): " & VbCrLf
	For Each vKey In oDictErr
		sOut = sOut & "Error " & vKey & " in oDictErr: " & oDictErr.Item(vKey) & VbCrLf
	Next
	MsgBox(sOut)
End Sub
' *** END SCRIPT ERROR HANDLER


' *** FILE INCLUDE HANDLER
' include file
Function kwIncludeFile(sFilePath)
	On Error Resume Next
	dim oFsoInc, oFileHandler, sIncContent
	Set oFsoInc = CreateObject ("Scripting.FileSystemObject")
	
	If sFilePath = "" Then: Exit Function: End If
	
	If NOT oFsoInc.FileExists(sFilePath) Then
		kwTriggerError("unable to load " & sFilePath & " : file not found")
		Exit Function
	End If
	
	Set oFileHandler = oFsoInc.OpenTextFile(sFilePath,1)
	If Err.number <> 0 Then
		kwTriggerError("file " & sFilePath & " could not be opened")
		Exit Function
	End If
	
	'MsgBox(sFilePath)	' debug
 	sIncContent = oFileHandler.ReadAll
 	oFileHandler.close
 	ExecuteGlobal sIncContent

	Set oFsoInc = Nothing
	Set oFileHandler = Nothing

End Function

' include all files
Sub kwIncludeFiles
	dim sFile
	For Each sFile In aINCLUDE
		kwIncludeFile(sFile)
	Next
End Sub

Call kwIncludeFiles
' Call kwDumpErrors


' Test
Dim oDataset, oDataset2, oDataset3, o3, sDatasetDump
Set oDataset = New vbDataset
Set oDataset2 = New vbDataset
Set oDataset3 = New vbDataset
Set o3 = CreateObject("Scripting.FileSystemObject")

Call oDataset.addDataset("wbem0", "value0")
Call oDataset.addDataset("wbem1", "value1")
Call oDataset.addDataset("wbem1", "value2")
Call oDataset.addDataset("wbem0", "value3")
MsgBox(oDataset.Dump())

Call oDataset2.addDataset("key1", 1)
Call oDataset2.addDataset("key2", "a string")
Call oDataset2.addDataset("key1", 2)

Call oDataset3.addDataset("dataset", oDataset2)
MsgBox(oDataset3.Dump())

Call oDataset.addDataset("wbem0", oDataset2)
Call oDataset.addDataset("wbem0", "value4")
Call oDataset.addDataset("wbem3", "value5")
Call oDataset.addDataset("wbem4", o3)
MsgBox(oDataset.printDatasetType())

' Test Next
MsgBox("oDataset.NextSet() -> as Do Loop While")
Dim aNextOut, aNextDataset, sIdxOut, sDsOut
oDataset.Reset()
Do While ( oDataset.NextSet() )
	aNextOut = oDataset.Index
	aNextDataset = oDataset.Dataset
	sDsOut = oDataset.printR(aNextDataset, aNextOut)
	MsgBox("oDatase.NextSet: " & vbCrLf & "index: " & aNextOut & vbCrLf & sDsOut)
	oDataset.Advance()
Loop


MsgBox(oDataset.Dump())

Set oDataset = Nothing

